package a01lnetAddressdemo;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * ClassName:    MyInnetAddressDemo1
 * Description:  网络编程：java.net包中InetAddress类的常用方法
 * Author:       于子续
 * Date:         2024/10/11 上午10:21
 * Version:      1.0
 **/
public class MyInnetAddressDemo1 {
    public static void main(String[] args) throws UnknownHostException {
        /*
        *确定主机名称的IP地址。主机名称可以是IP地址，也可以是主机名。
        * static InetAddress getByName(String host)
        *
        * 获取IP地址的主机名称。
        * String getHostName(InetAddress addr)
        *
        *返回文本显示中的IP地址字符串
        * String getHostAddress(InetAddress addr)
        * */

        //1.获取InetAddress对象
        InetAddress address = InetAddress.getByName("LAPTOP-S55Q5H1Q");
        System.out.println(address);

        //2.获取主机名称
        System.out.println(address.getHostName());

        //3.获取IP地址
        System.out.println(address.getHostAddress());

    }
}
